package com.eduprocess.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.eduprocess.entity.Clazz;
import com.eduprocess.entity.ClazzBlog;
import com.eduprocess.entity.Exam;
import com.eduprocess.entity.Grade;
import com.eduprocess.entity.School;
import com.eduprocess.entity.Student;
import com.eduprocess.entity.Teacher;
import com.eduprocess.entity.Term;
import com.eduprocess.viewmodel.JsonResult;
import com.eduprocess.viewmodel.Page;

@Controller
@RequestMapping(value = "/teacher")
public class TeacherController {
	/**
	 * 操作主界面
	 * 
	 * @return
	 */
	@RequestMapping(value = "/main")
	public String main(Model model) {

		// 用户信息 & 角色
		Teacher teacher = new Teacher();
		teacher.setTeacherId("111");
		teacher.setTeacherName("某 老师");
		model.addAttribute("teacher", teacher);

		// 学校
		School school = new School();
		school.setSchoolId("222");
		school.setSchoolName("八一中学");
		model.addAttribute("school", school);

		// 当前学年
		Term currentTerm = new Term();
		currentTerm.setTermId("2013");
		currentTerm.setTermName("2013-2014学年");
		model.addAttribute("term", currentTerm);

		// 列表 年级 & 班级 :: 当前学年
		Grade currentGrade = new Grade();
		currentGrade.setGradeId("222");
		currentGrade.setGradeName("G2016－高一");
		model.addAttribute("grade", currentGrade);

		List<Clazz> clazzes = new ArrayList<Clazz>();
		Clazz clazz = new Clazz();
		clazz.setGrade(currentGrade);
		clazz.setClazzId("0000");
		clazz.setClazzName("高一（8）班");
		clazzes.add(clazz);
		model.addAttribute("clazzes", clazzes);

		// 列表所有学年
		List<Term> terms = new ArrayList<Term>();
		terms.add(currentTerm);

		return "teacher/main";
	}

	/**
	 * 列表该年级的所有老师
	 * 
	 * @param gradeId
	 * @return
	 */
	@RequestMapping(value = "/json/listteacher")
	public @ResponseBody
	JsonResult listTeacher(String gradeId) {
		JsonResult jsonResult = new JsonResult();

		List<Teacher> teachers = new ArrayList<Teacher>();
		Teacher teacher = new Teacher();
		teacher.setTeacherId("111");
		teacher.setTeacherName("某某某");
		teacher.setEmail("xxx@sss.com");
		teacher.setMobile("135****8909");
		teachers.add(teacher);

		Page page = new Page();

		jsonResult.setObj(teachers);
		jsonResult.addObject("page", page);
		return jsonResult;
	}

	/**
	 * 获取教师信息
	 * 
	 * @param teacherId
	 * @return
	 */
	@RequestMapping(value = "/json/getteacher")
	public @ResponseBody
	JsonResult getTeacher(String teacherId) {
		JsonResult jsonResult = new JsonResult();

		Teacher teacher = new Teacher();
		teacher.setTeacherId("1111");
		teacher.setTeacherName("某木某");
		teacher.setEmail("xxx@sss.com");
		teacher.setMobile("135****8909");
		teacher.setPhone("010-938393300");
		teacher.setGender("男");

		jsonResult.setObj(teacher);
		return jsonResult;
	}

	/**
	 * 列表年级所有班级
	 * 
	 * @param gradeId
	 * @return
	 */
	@RequestMapping(value = "/json/listclazz")
	public @ResponseBody
	JsonResult listClazz(String gradeId) {
		JsonResult jsonResult = new JsonResult();

		List<Clazz> clazzes = new ArrayList<Clazz>();
		Clazz clazz = new Clazz();
		clazz.setClazzId("1111");
		clazz.setClazzName("高一8班");

		Teacher headTeacher = new Teacher();
		headTeacher.setTeacherId("2222");
		headTeacher.setTeacherName("某某某");
		clazz.setHeadTeacher(headTeacher);
		clazzes.add(clazz);

		Page page = new Page();

		jsonResult.setObj(clazzes);
		jsonResult.addObject("page", page);
		return jsonResult;
	}

	/**
	 * 列表年级考试
	 * 
	 * @param gradeId
	 * @return
	 */
	@RequestMapping(value = "/json/listexam")
	public @ResponseBody
	JsonResult listExam(String gradeId) {
		JsonResult jsonResult = new JsonResult();

		List<Exam> exams = new ArrayList<Exam>();
		Exam exam = new Exam();
		exam.setExamId("1111");
		exam.setExamName("期中考试");
		exams.add(exam);

		Page page = new Page();

		jsonResult.setObj(exams);
		jsonResult.addObject("page", page);
		return jsonResult;
	}

	/**
	 * 列表班级日志
	 * 
	 * @param clazzId
	 * @return
	 */
	@RequestMapping(value = "/json/listclazzblog")
	public @ResponseBody
	JsonResult listClazzBlog(String clazzId) {
		JsonResult jsonResult = new JsonResult();

		List<ClazzBlog> blogs = new ArrayList<ClazzBlog>();
		ClazzBlog clazzBlog = new ClazzBlog();

		blogs.add(clazzBlog);

		Page page = new Page();

		jsonResult.setObj(blogs);
		jsonResult.addObject("page", page);
		return jsonResult;
	}

	/**
	 * 列表班级学生
	 * 
	 * @param clazzId
	 * @return
	 */
	@RequestMapping(value = "/json/listclazzstudent")
	public @ResponseBody
	JsonResult listClazzStudent(String clazzId) {
		JsonResult jsonResult = new JsonResult();

		List<Student> students = new ArrayList<Student>();
		Student student = new Student();

		students.add(student);

		Page page = new Page();

		jsonResult.setObj(students);
		jsonResult.addObject("page", page);
		return jsonResult;
	}

}
